from django.db import models
import uuid
from base.models import App
class BaseModel(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, db_index=True, unique=True)
    app = models.ForeignKey(App, on_delete=models.CASCADE, related_name='%(class)s_app',db_index=True)
    created_at = models.DateTimeField(auto_now_add=True, db_index=True)
    updated_at = models.DateTimeField(auto_now=True)
    is_active = models.BooleanField(default=True)

    class Meta:
        abstract = True
    #重写删除方法，将is_active设置为False
    def delete(self, using=None, keep_parents=False):
        self.is_active = False
        self.save()
    
    #默认返回is_active为True的对象
    @classmethod
    def active_objects(cls):    
        return cls.objects.filter(is_active=True)